package com.survey.demo.ui.activity;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.hjq.widget.layout.WrapRecyclerView;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;
import com.survey.demo.R;
import com.survey.demo.app.AppActivity;
import com.survey.demo.app.AppAdapter;
import com.survey.demo.http.bean.SendBean;

import java.util.ArrayList;
import java.util.List;

/**
 *    author : Android 轮子哥
 *    github : https://github.com/getActivity/AndroidProject
 *    time   : 2018/10/18
 *    desc   : 优惠券
 */
public final class CouponActivity extends AppActivity implements OnRefreshLoadMoreListener {
    private SmartRefreshLayout mRefreshLayout;
    private WrapRecyclerView mRecyclerView;
    private CouponAdapter mAdapter;
    @Override
    protected int getLayoutId() {
        return R.layout.coupon_activity;
    }

    @Override
    protected void initView() {
        mRefreshLayout = findViewById(R.id.rl_status_refresh);
        mRecyclerView = findViewById(R.id.car_recycle);
        mAdapter = new CouponAdapter(this);
        mRecyclerView.setAdapter(mAdapter);
        mRefreshLayout.setOnRefreshLoadMoreListener(this);
    }

    @Override
    protected void initData() {
        List<String>  ss = new ArrayList<>();
        for(int i =0;i<3;i++){
            ss.add(i+"");
        }
        mAdapter.setData(ss);
    }
    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {
        postDelayed(() -> {
//            mAdapter.clearData();
//            mAdapter.setData(analogData());
            mRefreshLayout.finishRefresh();
        }, 1000);
    }

    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
        postDelayed(() -> {
            //mAdapter.addData(analogData());
            mRefreshLayout.finishLoadMore();

            //mAdapter.setLastPage(mAdapter.getItemCount() >= 100);
            //mRefreshLayout.setNoMoreData(mAdapter.isLastPage());
        }, 1000);
    }
    class CouponAdapter extends AppAdapter<String> {

        public CouponAdapter(Context context) {
            super(context);
        }

        @NonNull
        @Override
        public CouponAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            return new CouponAdapter.ViewHolder();
        }

        private final class ViewHolder extends AppAdapter<String>.ViewHolder {

            private final TextView tv_price;

            private ViewHolder() {
                super(R.layout.item_coupon);
                tv_price = findViewById(R.id.tv_price);
            }

            @Override
            public void onBindView(int position) {
                tv_price.setText(50+"");
            }
        }
    }
}